#include "MutableArrayContainer.cpp"
#include "MutableLinkedContainer.cpp"
#include <ctime>
#include <random>

int main()
{
    srand(time(0));
    MutableContainer<int> *container = new MutableArrayContainer<int>();

    for (int i = 0; i < 10; i++)
    {
        container->add(i);
    }

    std::cout << container->str() << std::endl;

    std::cout << container->remove(5) << std::endl;
    std::cout << container->str() << std::endl;

    std::cout << container->index(1) << std::endl;
    std::cout << container->str() << std::endl;

    std::cout << container->removeElement(8) << std::endl;
    std::cout << container->str() << std::endl;

    //    container->clear();
    //    std::cout << container->str() << std::endl;

    int ele = container->set(5, 500);
    std::cout << ele << std::endl;
    std::cout << container->str() << std::endl;

    ele = container->get(5);
    std::cout << ele << std::endl;
    std::cout << container->str() << std::endl;

    container->sort();
    std::cout << container->str() << std::endl;

    // 遍历
    int length = container->length();
    for (int i = 0; i < length; i++)
    {
        std::cout << container->get(i) << " ";
    }

    std::cout << std::endl;

    std::cout << "##########################################" << std::endl;

    container = new MutableLinkedContainer<int>();
    std::cout << container->str() << std::endl;
    container->add(12);
    std::cout << container->str() << std::endl;

    for (int i = 0; i < 10; i++)
    {
        container->add(rand() * 100 % 38);
    }

    std::cout << container->str() << std::endl;
    std::cout << container->length() << std::endl;

    container->add(5, 800);
    std::cout << container->str() << std::endl;
    std::cout << container->length() << std::endl;

    std::cout << container->remove(12) << std::endl;
    std::cout << container->str() << std::endl;
    std::cout << container->length() << std::endl;

    std::cout << container->removeElement(800) << std::endl;
    std::cout << container->str() << std::endl;
    std::cout << container->length() << std::endl;

    std::cout << container->removeElement(24) << std::endl;
    std::cout << container->str() << std::endl;
    std::cout << container->length() << std::endl;

    std::cout << container->set(100, 999) << std::endl;
    std::cout << container->str() << std::endl;
    std::cout << container->length() << std::endl;

    std::cout << "-----" << std::endl;
    int len = container->length();
    for (int i = 0; i < len; i++)
    {
        std::cout << container->get(i) << " ";
    }
    std::cout << std::endl;

    // container->clear();
    // std::cout << container->str() << std::endl;
    // std::cout << container->length() << std::endl;

    container->sort();
    std::cout << container->str() << std::endl;
    std::cout << container->length() << std::endl;

    return 0;
}
